let id = 0;
export default class Dep {
  constructor() {
    this.subs = [];
    this.id = id++;
  }
  //收集 watcher
  depend() {
    //this.subs.push(Dep.target);
    Dep.target.addDep(this);
  }
  addSub(watcher) {
    this.subs.push(watcher);
  }
  //更新所有watcher
  notify() {
    this.subs.forEach((watcher) => {
      watcher.updata();
    });
  }
}

Dep.target = null;
/** 添加watcher*/
let stack = []; //用栈 处理多个watcher 计算和页面的
export function pushTarget(watcher) {
  Dep.target = watcher;
  stack.push(watcher);
}
/** 取消watcher*/
export function popTarget() {
  stack.pop();
  Dep.target = stack[stack.length - 1];//获取前面的wathre
}
